﻿using Microsoft.AspNetCore.Mvc;
using StudentManager.API.BLL;
using StudentManager.Data;
using StudentManager.Data.IDAL;
using WebApplication1.Test;

namespace WebApplication1.Controllers
{
    [Route("[controller]/[action]")]
    [ApiController]
    public class OrderController : ControllerBase
    {
        private readonly IPayService _PayService;
        private readonly IStudentDAO _stuDAO;

        public OrderController([FromServices]IPayService pay, [FromServices]IStudentDAO studentDAO)
        {
            _PayService = pay;
            _stuDAO = studentDAO;
        }

        [HttpGet]
        public IActionResult GetList()
        {
            var list=_stuDAO.GetList();
            return Ok(Result.Data(list));
        }

        [HttpGet]
        public IActionResult OrderPay([FromQuery]int amount, [FromQuery]string orderId)
        {
            string payResult = "";
            var (success, payNo) = _PayService.Pay(amount, orderId);            
            if (success) payResult = $"订单{orderId}支付成功，支付单号：{payNo}";
            else payResult = $"订单{orderId}支付失败";
            return Ok(Result.OK(payResult));
        }      
    }
}
